var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util.js")), a = getApp();

Page({
    data: {
        tap: 1,
        name: "",
        phone: "",
        email: "",
        firm: "",
        uploadUrl: a.getNetAddresss("upload.uploadPic"),
        swlist: [],
        switch2: !1,
        num: 1,
        arr: [],
        type: "enroll",
        formid: "",
        default_deduction: 0,
        exchange_code_id: ""
    },
    onLoad: function(t) {
        console.log(t), this.setData({
            activity_id: t.id,
            exchange_code_id: t.exchange_code_id || ""
        });
    },
    postForm: function(t) {
        console.log(t);
        var i = {
            form_id: this.data.form_id,
            form_data: t.detail
        };
        if (this.data.count >= this.data.limit) wx.showToast({
            title: "报名人数已超过限制",
            icon: "none",
            duration: 1e3
        }); else {
            var d = this, e = a.getNetAddresss("plugin.diyform.api.diy-form.save-diy-form-data");
            a._postNetWork({
                url: e,
                showToastIn: !1,
                data: i,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? (d.setData({
                        "info.form_id": a.data.form_data_id
                    }), d.toNew()) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        }
    },
    toNew: function() {
        var t = this, i = {
            form_data_id: this.data.info.form_id,
            activity_id: this.data.activity_id,
            form_id: this.data.form_id
        };
        console.log(i);
        var d = a.getNetAddresss("plugin.activity-apply.api.Activity.getDiyForm");
        a._getNetWork({
            url: d,
            data: i,
            success: function(a) {
                var i = a.data;
                1 == i.result ? (t.data.exchange_code_id && (t.data.info.exchange_code_id = t.data.exchange_code_id), 
                t.notfree(t.data.info)) : wx.showToast({
                    title: i.msg,
                    duration: 500,
                    icon: "none"
                });
            }
        });
    },
    notfree: function(t) {
        var i = a.getNetAddresss("plugin.activity-apply.api.create");
        a._postNetWork({
            url: i,
            data: t,
            success: function(t) {
                var a = t.data;
                1 == a.result ? wx.navigateTo({
                    url: "/packageD/buy/orderPay/orderPay?order_id=" + a.data.order_ids + "&name=Myshaky"
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: "1000"
                });
            },
            fail: function(t) {}
        });
    },
    onChange: function(t) {
        var i = t.currentTarget.dataset.checked, d = t.currentTarget.dataset.ind;
        this.data.order_deductions[d].checked = !i, this.setData({
            order_deductions: this.data.order_deductions
        }), 1 == this.data.order_deductions[d].checked && this.data.arr.indexOf(t.currentTarget.dataset.name) <= -1 && this.data.arr.push(t.currentTarget.dataset.name), 
        0 == this.data.order_deductions[d].checked && this.data.arr.indexOf(t.currentTarget.dataset.name) > -1 && this.data.arr.splice(this.data.arr.indexOf(t.currentTarget.dataset.name), 1);
        var e = {
            address: JSON.stringify({}),
            dispatch_type_id: 0,
            goods_id: this.data.list.goods_id,
            total: this.data.num,
            option_id: "",
            orders: JSON.stringify([ {
                deduction_ids: this.data.arr,
                pre_id: this.data.pre_id
            } ]),
            member_coupon_ids: ""
        };
        0 != this.data.default_deduction && (e.no_deduction_ids = this.data.default_deduction);
        var o = a.getNetAddresss("order.goods-buy"), s = this;
        a._getNetWork({
            url: o,
            data: e,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    console.log(a), s.setData({
                        total_price: a.data.total_price,
                        pre_id: a.data.orders[0].pre_id,
                        order_deductions: a.data.orders[0].order_deductions
                    });
                    var i = {
                        orders: JSON.stringify([ {
                            deduction_ids: s.data.arr,
                            pre_id: s.data.pre_id
                        } ]),
                        dispatch_type_id: 0,
                        activity_id: s.data.activity_id,
                        test_uid: wx.getStorageSync("uid"),
                        lecturer_id: s.data.list.lecturer_id,
                        calssify_id: s.data.list.calssify_id,
                        goods: JSON.stringify([ {
                            goods_id: s.data.list.goods_id,
                            total: s.num,
                            option_id: 0
                        } ]),
                        form_id: ""
                    };
                    s.setData({
                        info: i
                    });
                } else wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    priceChange: function() {
        var t = this, i = a.getNetAddresss("order.goods-buy"), d = this, e = {
            address: JSON.stringify({}),
            dispatch_type_id: 0,
            goods_id: this.data.list.goods_id,
            total: this.data.num,
            option_id: "",
            orders: JSON.stringify([]),
            member_coupon_ids: ""
        };
        a._getNetWork({
            url: i,
            data: e,
            success: function(a) {
                var i = a.data;
                if (1 == i.result) {
                    for (var e in console.log(i), i.data.discount && i.data.discount.default_deduction && 0 != i.data.discount.default_deduction && (t.data.default_deduction = i.data.discount.default_deduction), 
                    d.setData({
                        total_price: i.data.total_price,
                        pre_id: i.data.orders[0].pre_id,
                        order_deductions: i.data.orders[0].order_deductions
                    }), d.data.order_deductions) if ("point" == d.data.order_deductions[e].code && 1 == d.data.order_deductions[e].checked) {
                        var o = [];
                        o.push("point"), d.setData({
                            arr: o
                        });
                    }
                    var s = {
                        orders: JSON.stringify([ {
                            deduction_ids: d.data.arr,
                            pre_id: d.data.pre_id
                        } ]),
                        dispatch_type_id: 0,
                        activity_id: d.data.activity_id,
                        test_uid: wx.getStorageSync("uid"),
                        lecturer_id: d.data.list.lecturer_id,
                        calssify_id: d.data.list.calssify_id,
                        goods: JSON.stringify([ {
                            goods_id: d.data.list.goods_id,
                            total: d.data.num,
                            option_id: 0
                        } ]),
                        form_id: ""
                    };
                    d.setData({
                        info: s
                    });
                } else wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.test();
        var t = getCurrentPages(), a = t[t.length - 2];
        console.log(a.route, t);
        var i = a.route;
        console.log(i, "path");
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            path: "/packageC/Myshaky/enroll/enroll?id=" + this.data.activity_id
        };
    },
    test: function() {
        var t = a.getNetAddresss("plugin.activity-apply.api.Activity.getActivityEnrol"), i = this;
        a._getNetWork({
            url: t,
            data: {
                activity_id: i.data.activity_id
            },
            success: function(t) {
                var d = t.data;
                if (d.data && 2 == d.data.enrol) return a.tips(d.msg), wx.navigateBack(), !1;
                1 == d.result ? (console.log(d), i.setData({
                    payStatus: d.data.enrol,
                    applyStatus: d.data.status
                }), wx.showToast({
                    title: d.msg,
                    icon: "none",
                    duration: 1e3
                }), i.getlist()) : (i.setData({
                    payStatus: 0
                }), i.getlist());
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getlist: function() {
        var i = a.getNetAddresss("plugin.activity-apply.api.Activity.getActivity"), d = this;
        a._getNetWork({
            url: i,
            data: {
                activity_id: d.data.activity_id
            },
            success: function(i) {
                var e = i.data;
                if (1 == e.result) {
                    console.log(e), e.data.start_time = t.default.formatTimeTwo(e.data.start_time, "Y/M/D h:m:s"), 
                    e.data.end_time = t.default.formatTimeTwo(e.data.end_time, "Y/M/D h:m:s"), d.setData({
                        list: e.data,
                        form_id: e.data.form_id,
                        total_price: e.data.cash
                    });
                    var o = d.data.list.has_many_pay_order.length > 0 ? d.data.list.has_many_pay_order[0].order_id : "", s = a._isTextEmpty(d.data.list.form_data_id) ? "" : d.data.list.form_data_id.form_data_id;
                    if (d.setData({
                        orderId: o,
                        form_data_id: s
                    }), console.log(Number(e.data.cash) > 0), Number(e.data.cash) > 0) d.priceChange(); else {
                        var r = {
                            dispatch_type_id: 0,
                            activity_id: d.data.activity_id,
                            test_uid: wx.getStorageSync("uid"),
                            lecturer_id: d.data.list.lecturer_id,
                            calssify_id: d.data.list.calssify_id,
                            goods: JSON.stringify([ {
                                goods_id: d.data.list.goods_id,
                                total: d.data.num,
                                option_id: 0
                            } ]),
                            form_id: ""
                        };
                        d.setData({
                            info: r
                        });
                    }
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});